package core.entities;

import javax.swing.ImageIcon;
import java.util.ArrayList;
import java.util.List;

/**
 * Class modeling the card
 * 
 * @author Nolan Potier
 * @version 1.0.0
 * 
 */
public enum Card {

	JUNGLE_SPEED_CARD_BACK("junglespeed", Symbol.SPECIAL, DifficultyLevel.SPECIAL),
	NULL_CARD(null, Symbol.SPECIAL, DifficultyLevel.SPECIAL),
    ROND_ROUGE("rond_rouge", Symbol.ROND, DifficultyLevel.EASY),
    ROND_BLEU("rond_bleu", Symbol.ROND, DifficultyLevel.EASY),
    ROND_VERT("rond_vert", Symbol.ROND, DifficultyLevel.EASY),
    ROND_JAUNE("rond_jaune", Symbol.ROND, DifficultyLevel.EASY),
    RECTANGLE_ROUGE("rect_rouge", Symbol.RECTANGLE, DifficultyLevel.EASY),
    RECTANGLE_BLEU("rect_bleu", Symbol.RECTANGLE, DifficultyLevel.EASY),
    RECTANGLE_VERT("rect_vert", Symbol.RECTANGLE, DifficultyLevel.EASY),
    RECTANGLE_JAUNE("rect_jaune", Symbol.RECTANGLE, DifficultyLevel.EASY),
    TRIANGLE_ROUGE("triangle_rouge", Symbol.TRIANGLE, DifficultyLevel.EASY),
    TRIANGLE_BLEU("triangle_bleu", Symbol.TRIANGLE, DifficultyLevel.EASY),
    TRIANGLE_VERT("triangle_vert", Symbol.TRIANGLE, DifficultyLevel.EASY),
    TRIANGLE_JAUNE("triangle_jaune", Symbol.TRIANGLE, DifficultyLevel.EASY),
    ECLAIR_ROUGE("eclair_rouge", Symbol.ECLAIR, DifficultyLevel.MEDIUM),
    ECLAIR_BLEU("eclair_bleu", Symbol.ECLAIR, DifficultyLevel.MEDIUM),
    ECLAIR_VERT("eclair_vert", Symbol.ECLAIR, DifficultyLevel.MEDIUM),
    ECLAIR_JAUNE("eclair_jaune", Symbol.ECLAIR, DifficultyLevel.MEDIUM),
    FLEUR_ROUGE("fleur_rouge", Symbol.FLEUR, DifficultyLevel.MEDIUM),
    FLEUR_BLEU("fleur_bleu", Symbol.FLEUR, DifficultyLevel.MEDIUM),
    FLEUR_VERT("fleur_vert", Symbol.FLEUR, DifficultyLevel.MEDIUM),
    FLEUR_JAUNE("fleur_jaune", Symbol.FLEUR, DifficultyLevel.MEDIUM),
    PENTAGONE_ROUGE("pentagone_rouge", Symbol.PENTAGONE, DifficultyLevel.MEDIUM),
    PENTAGONE_BLEU("pentagone_bleu", Symbol.PENTAGONE, DifficultyLevel.MEDIUM),
    PENTAGONE_VERT("pentagone_vert", Symbol.PENTAGONE, DifficultyLevel.MEDIUM),
    PENTAGONE_JAUNE("pentagone_jaune", Symbol.PENTAGONE, DifficultyLevel.MEDIUM),
    FLECHE_ROUGE("fleche_rouge", Symbol.FLECHE, DifficultyLevel.MEDIUM),
    FLECHE_BLEU("fleche_bleu", Symbol.FLECHE, DifficultyLevel.MEDIUM),
    FLECHE_VERT("fleche_vert", Symbol.FLECHE, DifficultyLevel.MEDIUM),
    FLECHE_JAUNE("fleche_jaune", Symbol.FLECHE, DifficultyLevel.MEDIUM);

    /**
     * Image of the card
     */
    private ImageIcon image;

    /**
     * Name of the card
     */
    private String name;
    
    /**
     * Symbol of the card
     */
    private Symbol symbol;

    /**
     * DifficultyLevel of the card
     */
    private DifficultyLevel level;

    /**
     * Path of the card
     */
    private static final String PATH = "../ressources/images/";

    /**
     * Normal constructor
     * 
     * @param name
     * @param level
     */
    Card(String name, Symbol symbol, DifficultyLevel level) {
        String path = Card.PATH + name + ".png";
        
        this.image = new ImageIcon(path);
        
        this.symbol = symbol;
        this.name = name;
        this.level = level;
    }

    /**
     * 
     * @return image image of the card
     */
    public ImageIcon getImage() {
        return image;
    }

    /**
     * 
     * @return name name of the card
     */
    public String getName() {
        return name;
    }

    /**
     * 
     * @return level level of the card
     */
    public DifficultyLevel getLevel() {
        return level;
    }
    
    /**
     * 
     * @return symbol symbol of the card
     */
    public Symbol getSymbol() {
        return symbol;
    }
    
    /**
     * getCardsByDifficultyLevel method<BR />
     * In game cards generation method. This method
     * is used to generate all the cards that will
     * be played during the game according to the
     * specified difficulty level.<BR />
     * The returned list is always in the same order,
     * the order will be randomized before the cards
     * are dealt.
     * 
     * @param difficultyLevel the difficulty level of the game
     * @return An ArrayList of all the cards that will be played.
     */
    public static List<Card> getCardsByDifficultyLevel(DifficultyLevel difficultyLevel) {
    	List<Card> cards = new ArrayList<Card>();
    	for (Card value : values()) {
    		if (value.getLevel().getLevelAsInteger() <= difficultyLevel.getLevelAsInteger()) {
    			cards.add(value);
    		}
    	}
    	return cards;
    }
}
